package edu.whu.xterm.http;

import java.net.URL;
import java.util.concurrent.Callable;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import android.content.Context;
import edu.whu.xterm.XApplication;

public class DocumentWorker implements Callable<Document> {

	private String url;

	private Context mContext;

	public DocumentWorker(Context ctx, String url) {
		mContext = ctx;
		this.url = url;
	}

	@Override
	public Document call() throws Exception {
		XApplication app = (XApplication) mContext;
		if (app.isLogined()) {
			HttpResponse resp = app.getHClient().execute(new HttpGet(url));
			return Jsoup.parse(resp.getEntity().getContent(), "GBK", url);
		}
		return Jsoup.parse(new URL(url), 10000);
	}

}
